package xyf.p11.other;

/**
 * ClassName: P0647_SubStr
 * Description:
 * Author: xyf
 * Date: 10/4/22 6:54 PM
 * Version: 1.0
 **/
public class P0647_SubStr
{
    public int countSubstrings(String s)
    {
        int ans = 0;
        //一个中心点
        for (int i = 0; i < s.length(); i++)
        {
            int left = i;
            int right = i;

            while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right))
            {
                left--;
                right++;
                ans++;
            }
        }

        //两个中心点
        for (int i = 0; i < s.length() - 1; i++)
        {
            int left = i;
            int right = i + 1;

            while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right))
            {
                left--;
                right++;
                ans++;
            }
        }
        return ans;
    }
}